enum {
PROP_0,
PROP_AUTOEXPAND,
+ PROP_MODEL,
PROP_PASSTHROUGH,
- PROP_ROOT_MODEL,
NUM_PROPERTIES
};
tree = node->children;
child = gtk_css_rb_tree_get_root (tree);
- while (TRUE)
+ while (child)
{
tmp = gtk_css_rb_tree_get_left (tree, child);
if (tmp)
child = gtk_css_rb_tree_get_right (tree, child);
}
- g_return_val_if_reached (NULL);
+ return NULL;
}
static guint
g_value_set_boolean (value, self->autoexpand);
break;
- case PROP_PASSTHROUGH:
- g_value_set_boolean (value, self->passthrough);
+ case PROP_MODEL:
+ g_value_set_object (value, self->root_node.model);
break;
- case PROP_ROOT_MODEL:
- g_value_set_object (value, self->root_node.model);
+ case PROP_PASSTHROUGH:
+ g_value_set_boolean (value, self->passthrough);
break;
default:
FALSE,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GtkTreeListModel:model:
+ *
+ * The root model displayed
+ */
+ properties[PROP_MODEL] =
+ g_param_spec_object ("model",
+ P_("Model"),
+ P_("The root model displayed"),
+ G_TYPE_LIST_MODEL,
+ GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
+
/**
* GtkTreeListModel:passthrough:
*
FALSE,
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_EXPLICIT_NOTIFY);
- /**
- * GtkTreeListModel:root-model:
- *
- * The root model displayed
- */
- properties[PROP_ROOT_MODEL] =
- g_param_spec_object ("root-model",
- P_("Root model"),
- P_("The root model displayed"),
- G_TYPE_LIST_MODEL,
- GTK_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY);
-
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
}
return self;
}
+/**
+ * gtk_tree_list_model_get_model:
+ * @self: a #GtkTreeListModel
+ *
+ * Gets the root model that @self was created with.
+ *
+ * Returns: (transfer none): the root model
+ **/
+GListModel *
+gtk_tree_list_model_get_model (GtkTreeListModel *self)
+{
+ g_return_val_if_fail (GTK_IS_TREE_LIST_MODEL (self), NULL);
+
+ return self->root_node.model;
+}
+
/**
* gtk_tree_list_model_get_passthrough:
* @self: a #GtkTreeListModel
* If @self is set to not be passthrough, this function is equivalent
* to calling g_list_model_get_item().
*
- * Returns: (nullable) (transfer: full): The row item
+ * Do not confuse this function with gtk_tree_list_model_get_child().
+ *
+ * Returns: (nullable) (transfer full): The row item
**/
GtkTreeListRow *
gtk_tree_list_model_get_row (GtkTreeListModel *self,
return tree_node_get_row (node);
}
+/**
+ * gtk_tree_list_model_get_child:
+ * @self: a #GtkTreeListModel
+ * @position: position of the child to get
+ *
+ * Gets the row item corresponding to the child at index @position for
+ * @self's root model.
+ *
+ * If @position is greater than the number of children in the root model,
+ * %NULL is returned.
+ *
+ * Do not confuse this function with gtk_tree_list_model_get_row().
+ *
+ * Returns: (nullable) (transfer full): the child in @position
+ **/
+GtkTreeListRow *
+gtk_tree_list_model_get_child (GtkTreeListModel *self,
+ guint position)
+{
+ TreeNode *child;
+
+ g_return_val_if_fail (GTK_IS_TREE_LIST_MODEL (self), NULL);
+
+ child = tree_node_get_nth_child (&self->root_node, position);
+ if (child == NULL)
+ return NULL;
+
+ return tree_node_get_row (child);
+}
+
/*** ROW ***/
enum {
ROW_PROP_0,
+ ROW_PROP_CHILDREN,
ROW_PROP_DEPTH,
ROW_PROP_EXPANDABLE,
ROW_PROP_EXPANDED,
switch (prop_id)
{
+ case ROW_PROP_CHILDREN:
+ g_value_set_object (value, gtk_tree_list_row_get_children (self));
+ break;
+
case ROW_PROP_DEPTH:
g_value_set_uint (value, gtk_tree_list_row_get_depth (self));
break;
gobject_class->get_property = gtk_tree_list_row_get_property;
gobject_class->dispose = gtk_tree_list_row_dispose;
+ /**
+ * GtkTreeListRow:children:
+ *
+ * The model holding the row's children.
+ */
+ row_properties[ROW_PROP_CHILDREN] =
+ g_param_spec_object ("children",
+ P_("Children"),
+ P_("Model holding the row's children"),
+ G_TYPE_LIST_MODEL,
+ GTK_PARAM_READABLE);
+
/**
* GtkTreeListRow:depth:
*
{
}
+/**
+ * gtk_tree_list_row_get_position:
+ * @self: a #GtkTreeListRow
+ *
+ * Returns the position in the #GtkTreeListModel that @self occupies
+ * at the moment.
+ *
+ * Returns: The position in the model
+ **/
+guint
+gtk_tree_list_row_get_position (GtkTreeListRow *self)
+{
+ g_return_val_if_fail (GTK_IS_TREE_LIST_ROW (self), 0);
+
+ if (self->node == NULL)
+ return 0;
+
+ return tree_node_get_position (self->node);
+}
+
/**
* gtk_tree_list_row_get_depth:
* @self: a #GtkTreeListRow
}
g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_EXPANDED]);
+ g_object_notify_by_pspec (G_OBJECT (self), row_properties[ROW_PROP_CHILDREN]);
}
/**
return tree_node_get_item (self->node);
}
+/**
+ * gtk_tree_list_row_get_children:
+ * @self: a #GtkTreeListRow
+ *
+ * If the row is expanded, gets the model holding the children of @self.
+ *
+ * This model is the model created by the #GtkTreeListModelCreateModelFunc
+ * and contains the original items, no matter what value
+ * #GtkTreeListModel:passthrough is set to.
+ *
+ * Returns: (nullable) (transfer none): The model containing the children
+ **/
+GListModel *
+gtk_tree_list_row_get_children (GtkTreeListRow *self)
+{
+ g_return_val_if_fail (GTK_IS_TREE_LIST_ROW (self), NULL);
+
+ if (self->node == NULL)
+ return NULL;
+
+ return self->node->model;
+}
+
+/**
+ * gtk_tree_list_row_get_parent:
+ * @self: a #GtkTreeListRow
+ *
+ * Gets the row representing the parent for @self. That is the row that would
+ * need to be collapsed to make this row disappear.
+ *
+ * If @self is a row corresponding to the root model, %NULL is returned.
+ *
+ * The value returned by this function never changes until the
+ * row is destroyed.
+ *
+ * Returns: (nullable) (transfer full): The parent of @self
+ **/
+GtkTreeListRow *
+gtk_tree_list_row_get_parent (GtkTreeListRow *self)
+{
+ TreeNode *parent;
+
+ g_return_val_if_fail (GTK_IS_TREE_LIST_ROW (self), NULL);
+
+ if (self->node == NULL)
+ return NULL;
+
+ parent = self->node->parent;
+ if (parent->is_root)
+ return NULL;
+
+ return tree_node_get_row (parent);
+}
+
+/**
+ * gtk_tree_list_row_get_child:
+ * @self: a #GtkTreeListRow
+ * @position: position of the child to get
+ *
+ * If @self is not expanded or @position is greater than the number of
+ * children, %NULL is returned.
+ *
+ * Returns: (nullable) (transfer full): the child in @position
+ **/
+GtkTreeListRow *
+gtk_tree_list_row_get_child (GtkTreeListRow *self,
+ guint position)
+{
+ TreeNode *child;
+
+ g_return_val_if_fail (GTK_IS_TREE_LIST_ROW (self), NULL);
+
+ if (self->node == NULL)
+ return NULL;
+
+ if (self->node->children == NULL)
+ return NULL;
+
+ child = tree_node_get_nth_child (self->node, position);
+ if (child == NULL)
+ return NULL;
+
+ return tree_node_get_row (child);
+}
+